/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __QS_DepositManager_H__
#define __QS_DepositManager_H__

#include "Prerequisites.h"
#include <QtCore/QDate>

namespace QSThink
{
	class DepositManager;

	//use pointer
	class DepositInfo
	{
	public:
		DepositInfo(QDate date,DepositCurrencyType currency,DepositAccountType account,int balance)
		{
			_date=date;
			_currency=currency;
			_account=account;
			_balance=balance;
		}

	
		QDate date(){
			return _date;
		}

		DepositCurrencyType currency(){
			return _currency;
		}

		DepositAccountType account(){
			return _account;
		}

		int balance(){
			return _balance;
		}

	protected:
		QDate _date;//start deposit date
		DepositCurrencyType _currency;
		DepositAccountType _account;
		int _balance;

	};

	class DepositListener
	{
	public:
		DepositListener();
	protected:
		friend class DepositManager;
		virtual void OnSymbolAdded(QString symbol)=0;
		virtual void OnSymbolRemoved(QString symbol)=0;

	};

	//should have portfolio history management
	//that need every symbol have a history file.
	//only one portfolio now allowed for simple and easy use.
	class DepositManager
	{
	public:
		static const QString FileName;

	public:
		DepositManager();
		static DepositManager& getSingleton();


		void removeDeposit(DepositInfo* info);

		DepositInfo* addDeposit(QDate date,DepositCurrencyType currency,DepositAccountType account,int balance);
		DepositInfo* getDeposit(int index);
		int getDepositCount();
		float getCapital();
		
	protected:
		friend class DepositListener;
		void addListener(DepositListener* listener);
		void persist();
		void loadDeposits();
	protected:
		std::vector<DepositInfo*> _deposits;
		std::vector<DepositListener*> _listeners;
	};
}


#endif
